﻿using System.Net.Mail;
//using System.Web.Mail;
using mal.balades.Business.Configuration;
using mal.balades.Business.Credential;
using System.Configuration;

namespace mal.balades.Business.Web
{
    public class MailHelper
    {
        private string tags = "[Balades]";
        private int? smtpPort;
        private string smtpHost;

       // private ConfigurationHelper configurationHelper;
        //TODO : rendre ce code plus testable
        public MailHelper()
        {
            smtpPort = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]);
            smtpHost = ConfigurationManager.AppSettings["SmtpHost"];

        }

        public void SendMailConstactUs(string from, string message)
        {
            SendMail(ConfigurationManager.AppSettings["AdministratorEmail"]
                , from, tags + " : Contactez-nous", message);
        }

        public void SendMail(string to, string from, string subject, string message)
        {
            MailMessage mail = new MailMessage(from, to);

            mail.IsBodyHtml = true;
            mail.Subject = subject;
            mail.Body = message;

            SmtpClient smtp = new SmtpClient(smtpHost);

            if (smtpPort.HasValue)
                smtp.Port = smtpPort.Value;

            smtp.Credentials = new CredentialsSmtp().GetCredential(string.Empty, 0, string.Empty);

            smtp.Send(mail);
        }


    }
}
